package jsyf.oa.dao.report.information;

import com.alibaba.fastjson.JSONObject;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 92852 on 2018/4/5.
 */
@Repository
public class PersonnelReportDao extends BaseDao {
    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return null;
    }

    public List<JSONObject> getRegionListByUserId(String userId) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT\n" +
                "\tv_sys_region.regionId,\n" +
                "\tv_sys_region.managerName,\n" +
                "\tv_sys_region.managerRoleName,\n" +
                "\tv_sys_region.managerId,\n" +
                "\tv_sys_region.managerJobState,\n" +
                "\tv_sys_region.regionName,\n" +
                "\tREPLACE (v_sys_region.bigRegionName, '大区', '') AS bigRegionName\n" +
                "FROM\n" +
                "\tv_sys_region\n" +
                " JOIN v_sys_user ON v_sys_region.managerDepartId=v_sys_user.departId  WHERE v_sys_user.id='" + userId + "' and v_sys_region.parentId=0 ");
        sb.append("AND v_sys_region.managerRoleName in('大区经理')  AND  v_sys_region.managerJobState<>1 ");
        sb.append("group by v_sys_region.managerId  ");
        sb.append("UNION  ");
        sb.append("SELECT\n" +
                "\t\tv_sys_region.regionId,\n" +
                "\tv_sys_region.managerName,\n" +
                "\tv_sys_region.managerRoleName,\n" +
                "\tv_sys_region.managerId,\n" +
                "\tv_sys_region.managerJobState,\n" +
                "\tv_sys_region.regionName,\n" +
                "\t\tREPLACE (v_sys_region.bigRegionName, '大区', '') AS bigRegionName\n" +
                "\tFROM\n" +
                "\t\tv_sys_region\n" +
                "JOIN v_sys_user ON v_sys_region.managerDepartId=v_sys_user.departId\n" +
                "\tWHERE\n" +
                "\t\t\tv_sys_user.id= '" + userId + "' and v_sys_region.parentId!=0 ");
        sb.append("AND v_sys_region.managerRoleName in('区域经理')  AND  v_sys_region.managerJobState<>1 ");
        sb.append("group by v_sys_region.managerId ");
        return queryForJsonList(sb.toString());
    }
}
